/*     */ package com.zimbra.cs.redolog;
/*     */ 
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import java.io.IOException;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class TransactionId
/*     */ {
/*     */   private int mTime;
/*     */   private int mCounter;
/*     */   
/*     */   public TransactionId(int time, int counter)
/*     */   {
/*  39 */     this.mTime = time;
/*  40 */     this.mCounter = counter;
/*     */   }
/*     */   
/*     */   public TransactionId() {
/*  44 */     this.mTime = 0;
/*  45 */     this.mCounter = 0;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public int compareTo(TransactionId b)
/*     */   {
/*  57 */     if (this.mTime == b.mTime) {
/*  58 */       if (this.mCounter < b.mCounter)
/*  59 */         return -1;
/*  60 */       if (this.mCounter > b.mCounter)
/*  61 */         return 1;
/*  62 */       return 0; }
/*  63 */     if (this.mTime < b.mTime) {
/*  64 */       return -1;
/*     */     }
/*  66 */     return 1;
/*     */   }
/*     */   
/*     */   public String toString()
/*     */   {
/*  71 */     return Integer.toString(this.mTime) + "." + Integer.toString(this.mCounter);
/*     */   }
/*     */   
/*     */   public void serialize(RedoLogOutput out) throws IOException {
/*  75 */     out.writeInt(this.mTime);
/*  76 */     out.writeInt(this.mCounter);
/*     */   }
/*     */   
/*     */   public void deserialize(RedoLogInput in) throws IOException {
/*  80 */     this.mTime = in.readInt();
/*  81 */     this.mCounter = in.readInt();
/*     */   }
/*     */   
/*     */   public boolean equals(Object obj)
/*     */   {
/*  86 */     TransactionId b = (TransactionId)obj;
/*  87 */     return (b != null) && (b.mTime == this.mTime) && (b.mCounter == this.mCounter);
/*     */   }
/*     */   
/*     */   public int hashCode()
/*     */   {
/*  92 */     return this.mCounter;
/*     */   }
/*     */   
/*     */   public int getTime() {
/*  96 */     return this.mTime;
/*     */   }
/*     */   
/*     */   public int getCounter() {
/* 100 */     return this.mCounter;
/*     */   }
/*     */   
/*     */   public String encodeToString() {
/* 104 */     StringBuilder sb = new StringBuilder();
/* 105 */     sb.append(this.mTime).append('-').append(this.mCounter);
/* 106 */     return sb.toString();
/*     */   }
/*     */   
/*     */   public static TransactionId decodeFromString(String str) throws ServiceException
/*     */   {
/* 111 */     Throwable cause = null;
/* 112 */     if (str != null) {
/* 113 */       String[] fields = str.split("-", 2);
/* 114 */       if ((fields != null) && (fields.length == 2)) {
/*     */         try {
/* 116 */           int time = Integer.parseInt(fields[0]);
/* 117 */           int counter = Integer.parseInt(fields[1]);
/* 118 */           return new TransactionId(time, counter);
/*     */         } catch (NumberFormatException e) {
/* 120 */           cause = e;
/*     */         }
/*     */       }
/*     */     }
/* 124 */     throw ServiceException.PARSE_ERROR("Invalid TransactionId " + str, cause);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/redolog/TransactionId.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */